trigger cxgSetPrimaryContactonRelatedAccount on Contact (after insert, after update) {

/* Declare a set to capture the ID's of the Accounts*/      
    list<contact> cntId = new list<contact>();
/* List to capture the list of contacts*/    
    List<Contact> ContactList = new List<Contact>();
    
    Id AASRecordTypeID = RecordTypeHelper.GetRecordTypeIDByDevName('contact','Standard_Contact_Record_Type');
    //Id ContactrecordTypeId = RecordTypeHelper.GetRecordTypeIdByDevName('Contact', 'Standard Contact Record Type'); 
    system.debug('IDDDDD ' +AASRecordTypeID );
    //Id AccountrecordTypeId = RecordTypeHelper.GetRecordTypeIdByDevName('Account', 'Standard Account Record Type'); 
    
    if(trigger.isUpdate){
        system.debug('I am inside first if');    
    for(Contact cnt: Trigger.New){
    system.debug(cnt.recordtypeid);
    if(cnt.IsPrimary_Contact__c==True && cnt.recordtypeid == AASRecordTypeID ){
        system.debug('TTT');
        cntId.add(cnt);
        }
        system.debug('AAAAAAAAAAAAAAA'+cntId);
    }
    }
    
    for(Contact cnt: [select id, account.cxg_contact__C from contact where id in: cntId]){
        cnt.account.CxG_Contact__c = cnt.id;
        ContactList.add(cnt);
        }
try{
update ContactList;
system.debug('Updated '+ContactList);
}
Catch (dmlexception e){
System.debug('Exception occured'+e);
}
}